﻿namespace eProject.ViewModel.Commands
{
    public class CreateTaskCommand: ICommand
    {
        private readonly CommonManager _manager;
        private readonly string _name;
        private readonly string _description;
        private readonly long _duration;


        private bool _isCanceled;
        private bool _isExecuted;

        public CreateTaskCommand(CommonManager manager, string name, string description, long duration)
        {
            _manager = manager;
            _name = name;
            _description = description;
            _duration = duration;
        }

        public void Execute()
        {
            if (_isExecuted) return;
            _manager.CreateTask(_name, _description, _duration);
            _isExecuted = true;
            _isCanceled = false;
        }

        public void Unexecute()
        {
            if (_isCanceled) return;
            var task = _manager.GetTask(_name);
            _manager.DeleteTask(task);
            _isCanceled = true;
            _isExecuted = false;
        }
    }
}
